// 省份和城市 cities
export default {
	data() {
		return {
			// 省份
			provinces: {
				form: {},
				list: [],
			},
			// 城市
			cities: {
				form: {},
				list: []
			}
		}
	},
	methods: {
		// 省份
		getProvince(name) {
			let _data = {}
			if (name) {
				_data.name = name
			}
			else {
				_data.name = ''
			}
			api.getProvince(_data)
				.then(res => {
					this.provinces.list = res
				})
				.catch(res => {
					console.log(res)
				})
		},
		provinceChange(val) {
			if (val) {
				this.cities.form = {}
				this.cities.list = []
				this.getCity(val)
			}
		},
		// 城市
		getCity(pid, name) {
			let _data = {}
			if (pid) {
				_data.idProvince = pid
			}
			if (name) {
				_data.name = name
			}
			api.getCity(_data)
				.then(res => {
					this.cities.list = res
				})
				.catch(res => {
					console.log(res)
				})
		}
	}
}